#coding=utf-8
"""
===========================
Author:李灵娜
Time:2023/3/24 14:39
website:https://duoceshi.net
===========================
"""
import sys
sys.path.append('..')
import unittest
from time import *
# from  selenium import webdriver
# driver = webdriver.Chrome()

class BasePage(unittest.TestCase):
    @classmethod
    def set_driver(cls,driver):
        cls.driver = driver

    @classmethod
    def get_driver(cls):
        return cls.driver


    #baidu_input('id','kw')
    @classmethod
    def find_element(cls,element):
        type = element[0]
        value = element[1]
        if type =="id":
            elem =cls.driver.find_element_by_id(value)
        elif type == "xpath":
            elem=cls.driver.find_element_by_xpath(value)
        elif type =="class":
            elem =cls.driver.find_elements_by_class_name(value)
        elif type =="name":
            elem =cls.driver.find_element_by_name(value)
        elif type =="css":
            elem =cls.driver.find_element_by_css_selector(value)
        elif type =='link_text':
            elem =cls.driver.find_element_by_link_text(value)
        elif type =="partial":
            elem =cls.driver.find_element_by_partial_link_text(value)
        elif type=='css':
            elem=cls.driver.find_element_by_css_selector(value)
        elif type =='js':
            elem=cls.driver.execute_script(value)

        else:
            raise ValueError('plese input corrt paramters')
        return elem
    @classmethod
    def sendKeys(cls,elem,text):
        return elem.send_keys(text)
    @classmethod
    def click(cls,elem):
        return elem.click()
    @classmethod
    def wailt(cls,sec):
        return cls.driver.implicitly_wait(sec)

    @classmethod
    def frame(cls, elem):
        return cls.driver.switch_to.frame(elem)

    @classmethod
    def outframe(cls):
        return cls.driver.switch_to.default_content()

    @classmethod
    def sleep(cls, sec):
        return sleep(sec)

    @classmethod
    def get_text(cls, element):
        value =BasePage.find_element(element).text
        return value
    @classmethod
    def refresh(cls):
        cls.driver.refresh()
if __name__ == '__main__':
    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.get("http://www.baidu.com")
    driver.maximize_window()
    baidu_input=('id','kw')
    elem =BasePage.find_element(baidu_input)
    BasePage.sendKeys(elem,'多测师')
    baidu_click =('id','su')
    elem =BasePage.find_element(baidu_click)
    elem.click()






